<template>
    <div id="OrdersTitle">
        <v-details :inputConfig="inputConfig" :detailData="inputData" :rules="rules" @pop="setData"
                   ref="input"></v-details>
    </div>
</template>

<script>
    import details from 'commons/Detail'
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        props: {
            inputData: {
                type: Object,
            }
        },
        mixins: [baseMixin],
        name: "OrdersTitle",
        data() {
            return {
                addflag: false,
                rules: {
                    uom_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    uom_desc: [
                        {required: true, trigger: 'blur'},
                    ],
                    uom_type_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    per_of_field: [
                        {required: true, trigger: 'blur'},
                    ],
                    measure_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    measure_uom: [
                        {required: true, trigger: 'blur'},
                    ],
                },
            }
        },
        computed: {
            inputConfig() {
                return [
                    [
                        {
                            type: "input",
                            label: "计量单位代码",
                            props: "uom_code",
                            disabled: this.addflag
                        },
                        {
                            type: "input",
                            label: this.$t('common.desc'),
                            props: "uom_desc",
                        },
                        {
                            type: "select",
                            label: "计量单位类型",
                            props: "uom_type_code",
                            options: this.getOptions("codelkup/UOMTYPE"),
                        },
                        {
                            type: "input",
                            label: "字段百分比",
                            props: "per_of_field",
                        }
                    ],
                    [
                        {
                            type: "select",
                            label: "计量系统",
                            props: "measure_code",
                            options: this.getOptions("codelkup/MEASURESYS")
                        },
                        {
                            type: "table",
                            label: this.$t('config.measureUnit'),
                            props: "measure_uom",
                            tableConfig: [
                                {
                                    label: "计量单位代码",
                                    prop: "uom_code",
                                    input: "input",
                                },
                                {
                                    label: "计量单位说明",
                                    prop: "uom_desc",
                                    input: "input",
                                }
                            ],
                            url: `/queryUomListByCode/${this.inputData.uom_type_code}/${this.inputData.measure_code}/?/${this.$store.state.wms}`,
                            disabled: this.flag,
                        },
                        {
                            type: "input",
                            label: "计量单位说明",
                            props: "measure_uom_name",
                            disabled: true
                        },
                    ]
                ]
            },
            flag() {
                if (this.inputData.uom_type_code == "" || this.inputData.measure_code == "") {
                    return true;
                } else {
                    return false;
                }
            }
        },
        methods: {
            setData(data, id, close, listId) {
                this.inputData.measure_uom = data.uom_code;
                this.inputData.measure_uom_name = data.uom_desc;
                close(false);
            }
        },
        mounted() {
            if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                if (!data.newFlag) {
                    this.addflag = true;
                }
            } else if (!this.$store.state.newFlag) {
                this.addflag = true;
            }
        },
        watch: {},
        components: {
            'v-details': details
        }
    }
</script>

<style scoped>

</style>
